/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MemberDetails;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Login.*;
/**
 *
 * @author Bharath
 */
public class AJAXGetMemDetails extends HttpServlet {

    MySqlConnector ms = new MySqlConnector();
    private Connection con;
    private PreparedStatement ps;

    public AJAXGetMemDetails() {
        System.out.println("HEllo**********");
    }
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, Exception {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            System.out.println("***In GetMEmDetails class***");
            String state = request.getParameter("state");
            String prof = request.getParameter("prof");
            String district = request.getParameter("district");
            //String mandal = request.getParameter("mandal");
            con = ms.Connect();
            String s1 = "select memberid, name, surname,mobile, email from registration  " +
                    "where prof = '" + prof + "' and state = '" + state
                    + "' and dist = '" + district + "' ;" ;
           // and mandal = '"+ mandal + "' ;";
            ps = con.prepareStatement(s1);
            System.out.println("Query in DAO..........." + s1);
            ResultSet rs = ps.executeQuery();
            out.println(" Names   |   Desig  |  Address  |  Ph No. | Email ");
            while (rs.next() == true) {
                System.out.println(".................................");
                out.println(rs.getString(1) + "   |   " + rs.getString(2)+ "." +rs.getString(3) + "  |  " + rs.getString(4) + "  |  " + rs.getString(5)+ " | " + "&");
                System.out.println("................................");
                System.out.println(rs.getString(1) + "@" + rs.getString(2) + "@" + rs.getString(3) + "@" + rs.getString(4) + "@" + rs.getString(5));
            } 
        } catch (Exception e) {
            System.out.println("Exception " + e);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(AJAXGetMemDetails.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(AJAXGetMemDetails.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
